﻿//-----------------------------------------------------------------------
// <copyright file="ServiceCollectionExtensions.cs" company="SLWY Enterprises">
// * Copyright (C) 2017 四川商旅无忧科技有限公司 版权所有。
// * version : 1.0
// * author  : qinchaoyue
// * FileName: ServiceCollectionExtensions.cs
// * history : created by qinchaoyue 2017-10-22 09:39:01
// </copyright>
//-----------------------------------------------------------------------

using Microsoft.Extensions.Configuration;
using Slwy.Logger.Models;

namespace Slwy.Logger
{
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;

    using Slwy.Logger.Implements.Elasticsearch;
    using Slwy.Logger.Implements.Log4Net;
    using Slwy.Utility.ConfigurManager;

    /// <summary>
    /// 注入服务扩展方法
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// 注册日志服务
        /// </summary>
        /// <param name="services">服务集合</param>
        /// <param name="configuration">配置</param>
        public static void AddLoggerService(this IServiceCollection services, IConfiguration configuration)
        {
            var logOptions = configuration.GetSection("Logging");
                //new ConfigurHandler().GetSection("Logging");
            services.Configure<LogOptions>(logOptions);
            services.AddSingleton<CustomRollingFileLogger>();
            services.AddSingleton<Contracts.ILogger, Log4NetLog>();
        }
    }
}
